<?php
if(!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

/*
 *团队操作
 *@author 王春林
 */
class team extends MY_Controller {
	function __construct() {
		parent::__construct();
		$this->load->helper('url');
		$this->load->model('team_model');
	}
	
	function index($teamId) {
		$this->getHeader('header03');
		$rs = $this->team_model->queryTeamByTeamId($teamId);
		//$rs = $this->team_model->queryTeamByTeamId(2);
		$data['rs']=$rs;
		
		$this->load->view('list_tdzy',$data);
	}
	function teamYearbook($teamId){
		$results = $this->team_model->listUsersByTeamId($teamId);
		$data['users'] = $results;
		$rs = $this->team_model->queryTeamByTeamId($teamId);
		$data['rs']=$rs;
		$this->getHeader("header03");
		$this->load->view("team_yearbook",$data);
	}
	
	function teamPhotowall($teamId){
		$results = $this->team_model->listUsersByTeamId($teamId);
		$data['users'] = $results;
		$rs = $this->team_model->queryTeamByTeamId($teamId);
		$data['rs']=$rs;
		$this->getHeader("header03");
		$this->load->view("team_photowall",$data);
	}
	
	function countUsersDynamic($teamId,$type) {
		$counts = $this->team_model->countUsersDynamic($teamId,$type);
		$data['counts'] = $counts;
		$this->load->view("list_tdzy",$data);
	}
	/**
	 *用户动态
	 */
	function dynamic_links($teamId,$type,$pageNo) {
		$userDynamic = $this->team_model->lookUsersDynamic($teamId,$type,$pageNo);
		$data['userDynamic'] = $userDynamic;
	
		$data['teamId'] = $teamId;
		if(empty($userDynamic)){
			return;
		}
		if($type=="image") {
			$this->load->view('link_picture',$data);
		} else if($type=="text") {
			$this->load->view('link_text',$data);
		} else if($type=="links") {
			$this->load->view('link_links',$data);
		} else if($type=="video") {
			$this->load->view('link_video',$data);
		}
	}
	
	/**
	 *创建团队
	 */
	function createTeam() {
		$team = $_POST;
		if(!empty($team)){
			$team['userId'] = $this->session->userdata("userId");
			//$team['userNickname'] = 'admin';
			$team['createTime'] = date('Y-m-d H:i:s');
			$team['updateTime'] = date('Y-m-d H:i:s');
			$teamId = $this->team_model->createTeam($team);
		}
		$this->index($teamId);
	}
	/**
	 *团队名称是否可用
	 */
	function teamNameIsExist() {
		$teamName = $_POST['teamName'];
		$result = $this->team_model->teamNameIsExist($teamName);
		echo $result;
	}
	/**
	 *查询团队中的所有成员
	 */
	function listUserByTeamId() {
		$teamId = $_POST['teamId'];
		$this->team_model->listUsersByTeamId($teamId);
	}
	/**
	 *申请加入团队
	 */
	function applyJoinToTeam() {
		$teamId = $_POST['teamId'];
		$loginId = $this->session->userdata("userId");
		$currentTeam = $this->team_model->queryTeamByTeamId($teamId);
		$teamNickname = $currentTeam['teamNickname'];
		$this->team_model->applyJoinToTeam($loginId,$teamId,$teamNickname);
	}
	/**
	 *看好
	 */
	function optimistic() {
		$teamId = $_POST['teamId'];
		$this->team_model->optimistic($teamId);
	}
	/**
	 *在意
	 */
	function care() {
		$teamId = $_POST['teamId'];
		$this->team_model->care($teamId);
	}
	/**
	 *查看好友动态,根据teamId 查询所有用户发表的动态消息
	 */
	function lookUsersDynamic() {
		$teamId = $_POST['teamId'];
		$results = $this->team_model->lookUsersDynamic($teamId);
		$data['rs'] = $results;
		return $data;
	}
	/**
	 *回复用户动态
	 */
	function replayUsersDynamic() {
		$data['dynamicId'] = $_POST['dynamicId'];
		$data['reply_content'] = $_POST['reply_content'];
		$data['reply_time'] = date("Y-m-d H:i:s");
		$data['reply_userId'] = $this->session->userdata("userId");
		$this->team_model->replayUsersDynamic($data);
	}
	/**
	 *转发用户动态
	 */
	function forward() {
		$dynamicId = $_POST['dynamicId'];
		$loginId = $this->session->userdata("userId");
		$this->team_model->forward($loginId,$dynamicId);
	}
	/**
	 *根据用户动态ID查询当前动态内容及回复
	 */
	function queryDynamicContent($dynamicId,$teamId) {
		$data['ud'] = $this->team_model->queryUserDynamicById($dynamicId);
		$data['dynamicReply'] = $this->team_model->queryDynamicReplyById($dynamicId);
		$rs = $this->team_model->queryTeamByTeamId($teamId);
		$data['rs']=$rs;
		$this->load->view("list_tdContent",$data);
	}
	/**
	 *更新公告
	 */
	function updateDynamicNotice() {
		$content = $_POST['content'];
		$teamId = $_POST['teamId'];
		$this->team_model->updateDynamicNotice($content,$teamId);
	}
	/**
	 *更新简介
	 */
	function updateDynamicDesc() {
		$content = $_POST['content'];
		$teamId = $_POST['teamId'];
		$this->team_model->updateDynamicDesc($content,$teamId);
	}
	/**
	 *查询某团队下的所有成员
	 */
	function listUsersByTeamId($teamId) {
		$results = $this->team_model->listUsersByTeamId($teamId);
		$data['users'] = $results;
		$rs = $this->team_model->queryTeamByTeamId($teamId);
		$data['rs']=$rs;
		$this->getHeader("header03");
		$this->load->view("list_tdcy",$data);
	}
	
	function teamPhotowallDiv($teamId,$beginNumber,$pageSize) {
		$team['photowallRelegation']=$teamId;
		$team['photowallType']=0;
		$team['deleFlag']=0;
		$this->load->model ( "photowall_model" );
		$array = $this->photowall_model->queryPersonalYearbook ( $team, $beginNumber, $pageSize );
		$data ['team'] ['result'] = json_encode ( $array );
		$data ['team'] ['description'] = "团队图片";
		$divCode = $this->getHomeDynamicDiv ( $data, 1, 'photowall' );
		echo $divCode;
	}
}
?>